//
//  HeaderView.m
//  AgriMobile
//
//  Created by 春名 啓作 on 11/05/28.
//  Copyright 2011 e-agri. All rights reserved.
//

#import "HeaderView.h"


@implementation HeaderView


- (id)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
		self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code.
}
*/

- (void)drawRect:(CGRect)rect
{
    // CGContextを用意する
    CGContextRef context = UIGraphicsGetCurrentContext();
	
    // CGGradientを生成する
    // 生成するためにCGColorSpaceと色データの配列が必要になるので
    // 適当に用意する
    CGGradientRef gradient;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

	CGFloat locations[2] = { 0.0, 1.0 };
    /*
    
    CGFloat components[8] = { 1.0, 1.0, 1.0, 1.0,  // Start color
		0.79, 0.79, 0.79, 1.0 }; // End color
	 */
    //gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
	
	//C9E6B7
	UIColor *colorG = HEXCOLOR(0xc9e6b7);
	CGColorRef colorArray[2] = {[colorG CGColor],
								[[UIColor clearColor] CGColor]};
	CFArrayRef colors = CFArrayCreate(kCFAllocatorDefault, (const void **)colorArray, 2, &kCFTypeArrayCallBacks);
	gradient = CGGradientCreateWithColors(colorSpace, colors, locations);

	CGPoint startPoint = CGPointMake(self.frame.size.width/2, 0.0);
    CGPoint endPoint = CGPointMake(self.frame.size.width/2, self.frame.size.height);
    CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
	
    // GradientとColorSpaceを開放する
    CGColorSpaceRelease(colorSpace);
    CGGradientRelease(gradient);
}

- (void)dealloc {
    [super dealloc];
}


@end
